package site.sorghum.ddl.field;

import java.sql.JDBCType;

public class BasicTypeConverter implements TypeConverter {
    public static final TypeConverter INSTANCE = new BasicTypeConverter();

    @Override
    public String convertToDatabaseType(JDBCType jdbcType) {
        if (jdbcType == null) {
            throw new IllegalArgumentException("JDBC type cannot be null");
        }
        switch (jdbcType) {
            case BIT:
                return "BIT";
            case TINYINT:
                return "TINYINT";
            case SMALLINT:
                return "SMALLINT";
            case INTEGER:
                return "INT";
            case BIGINT:
                return "BIGINT";
            case FLOAT:
                return "FLOAT";
            case REAL:
                return "REAL";
            case DOUBLE:
                return "DOUBLE";
            case NUMERIC:
                return "NUMERIC";
            case DECIMAL:
                return "DECIMAL";
            case CHAR:
                return "CHAR";
            case VARCHAR:
                return "VARCHAR";
            case LONGVARCHAR:
                return "TEXT";
            case DATE:
                return "DATE";
            case TIME:
                return "TIME";
            case TIMESTAMP:
                return "DATETIME";
            case BINARY:
                return "BINARY";
            case VARBINARY:
                return "VARBINARY";
            case LONGVARBINARY:
                return "LONGBLOB";
            case NULL:
                return "NULL";
            case OTHER:
                return "OTHER";
            case JAVA_OBJECT:
                return "JAVA_OBJECT";
            case DISTINCT:
                return "DISTINCT";
            case STRUCT:
                return "STRUCT";
            case ARRAY:
                return "ARRAY";
            case BLOB:
                return "BLOB";
            case CLOB:
                return "CLOB";
            case REF:
                return "REF";
            case DATALINK:
                return "DATALINK";
            case BOOLEAN:
                return "BOOLEAN";
            case ROWID:
                return "ROWID";
            case NCHAR:
                return "NCHAR";
            case NVARCHAR:
                return "NVARCHAR";
            case LONGNVARCHAR:
                return "LONGNVARCHAR";
            case NCLOB:
                return "NCLOB";
            case SQLXML:
                return "SQLXML";
            case REF_CURSOR:
                return "REF_CURSOR";
            case TIME_WITH_TIMEZONE:
                return "TIMESTAMP";
            case TIMESTAMP_WITH_TIMEZONE:
                return "TIMESTAMP";
            default:
                throw new IllegalArgumentException("Unsupported JDBC type: " + jdbcType);
        }
    }
}
